<template>
	<view class="user clearfix  bg-shop hv100">
		<cu-custom bgColor="bg-white " isBack>
			<block slot="content">个人资料</block>
		</cu-custom>
		<view class="flex align-center justify-between px15 f16 bg-white mt5 py20" @click="uploadPassport">
			<view class="flex align-center">头像</view>
			<view class="flex align-center justify-end" >
				<image :src="isfrz" class="block45 mr10 round" mode=""></image>
				<text class="cuIcon-right"></text>
			</view>
		</view>
		<view class="flex align-center justify-between px15 f16 bg-white mt1 py20" >
			<view class="flex align-center">ID</view>
			<text class="">{{userInfo.uid}}</text>
		</view>
		<!-- <view class="flex align-center justify-between px15 f16 bg-white mt1 py20">
			<view class="flex align-center">介绍人</view>
			<text class="">张敏</text>
		</view> -->
		<view class="flex align-center justify-between px15 f16 bg-white mt5 py20">
			<view class="flex align-center">邀请码</view>
			<text class="">{{userInfo.tjmNum}}</text>
		</view>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import uploadFile from '@/mixins/uploadFile'
export default {
	mixins: [uploadFile],
	data() {
		return {
			uploadpic:'',
			isfrz: ''
		}
	},
	computed: {
		...mapState(['userInfo','baseURL'])
	},
	
	methods: {
		...mapActions(['logout','getUser']),
		async uploadPassport() {
			let [err, res] = await uni.chooseImage({
				count: 1,
				sizeType: ['compressed'],
				sourceType: ['album']
			})
			if (res) {
				this.uploadpic = res.tempFilePaths.shift()
				this.up()
			}
		},
		async up(){
			let formData = {  }
			if (this.uploadpic) {
				let {
					data: { updateToken, updateUrl, prefixUrl }
				} = await this.$http.post('user.getQnToken', {}, { tipConfig: { storeLoading: true } })
				let img = await this.qnUploadFile({ url: updateUrl, prefixUrl, files: this.uploadpic, formData: { token: updateToken } })
				formData.headImg = img[0]
			}
			await this.$http.post('user.saveinfo', formData, { tipConfig: { storeLoading: true, isSuccessTip: true} })
			this.getUser()
		},
		// uploadImg() {
		// 	if(this.isfrz) {
		// 		let {
		// 			data: { updateToken, updateUrl, prefixUrl }
		// 		} = await this.$http.post('user.getQnToken', {}, { tipConfig: { storeLoading: true } })
		// 		let img = await this.qnUploadFile({ url: updateUrl, prefixUrl, files: this.isfrz, formData: { token: updateToken } })
		// 		this.imghead = img[0]
		// 	}
			
			
			// var _this = this;
			// // 选择图片 获取图片路径
			// uni.chooseImage({
			// 	count: 1, //默认9
			// 	sizeType: [ 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			// 	sourceType: ['album'], //从相册选择
			// 	success: function (res) {
			// 		// console.log(res.tempFilePaths)
			// 		uni.showLoading({
			// 			title: '上传图片',
			// 			mask: false
			// 		});
			// 		// 从本地获取图片完毕 上传
			// 		uni.uploadFile({
			// 			url: 'https://api.meidaojia.vip/api/manager/customer/upload', 
			// 			filePath: res.tempFilePaths.toString(),
			// 			name: 'avatar',
			// 			formData: {
			// 				token : uni.getStorageSync('token'),
			// 			},
			// 			success: (res) => {
			// 				let datas = JSON.parse(res.data);
			// 				_this.new_person_photo = datas.data.path
			// 				_this.no_had_upload = false;
			// 				_this.had_upload = true;
			// 			},
			// 			fail: (e) => {
			// 				console.log("网络请求fail");
			// 			},
			// 			complete: () => {
			// 				console.log("网络请求complete");
			// 				uni.hideLoading();
			// 				uni.showToast({
			// 					title: '上传成功！',
			// 					icon: 'none'
			// 				});
			// 			}
			// 		});
			// 	}
			// });
			
			
			
			// uni.chooseImage({
			// 	success: (chooseImageRes) => {
			// 		const tempFilePaths = chooseImageRes.tempFilePaths;
			// 		uni.uploadFile({
			// 			url: 'https://www.example.com/upload', //仅为示例，非真实的接口地址
			// 			filePath: tempFilePaths[0],
			// 			name: 'file',
			// 			formData: {
			// 				'user': 'test'
			// 			},
			// 			success: (uploadFileRes) => {
			// 				console.log(uploadFileRes.data);
			// 			}
			// 		});
			// 	},
			// 	fail:function(res){
			// 		console.log("用户取消上传文件")
			// 	}
			// });
		// }
	}
}
</script>

<style lang="less">
.mt1s{
	margin-top: 1rpx;
}
.set-button{
	width: calc(100% - 60rpx);
	margin-left: 30rpx;
	height: 102rpx;
	background-color:#FE4725;
	color: #FFFFFF;
	border-radius: 40rpx;
	position: fixed;
	bottom: 40rpx;
}
</style>


